package com.ling.module1sbbyyds.utils;

import com.ling.sbbyyds.entity.users.User;

import java.util.Map;

public class UserThreadLocal {

    private UserThreadLocal(){}

    private static final ThreadLocal<Map<String,Object>> LOCAL = new ThreadLocal<>();

    public static void put(Map<String,Object> data){
        LOCAL.set(data);
    }
    public static Map<String,Object> get(){
        return LOCAL.get();
    }

    /**
     * 获取该请求的用户信息
     * @return 返回用户信息
     */
    public static User getCurrentUser(){
       return (User) LOCAL.get().get("user");
    }

    /**
     * 获取该请求的token码
     * @return 返回token码
     */
    public static String getCurrentUserToken(){
        return (String) LOCAL.get().get("token");
    }
    public static void remove(){
        LOCAL.remove();
    }
}